package com.liaoban.app.ui.mine;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.ImageView;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.liaoban.app.R;
import com.liaoban.app.adapter.FollowAdapter;
import com.liaoban.app.api.type.Follow;
import com.liaoban.app.api.type.request.WuserinfoRequest;
import com.liaoban.app.biz.CommonBiz;
import com.liaoban.app.helper.ToastHelper;
import com.liaoban.app.ui.anchor.AnchorDetailActivity;
import com.liaoban.app.ui.base.BaseListActivity;
import com.liaoban.app.ui.login.LoginActivity;

import butterknife.BindView;

/**
 * Created by ybc on 2018/7/10 0010.
 * 粉丝
 */
public class FansActivity extends BaseListActivity<Follow> {
    @BindView(R.id.iv_right)
    ImageView ivRight;

    @Override
    public String getNewTitle() {
        return getString(R.string.fans);
    }

    @Override
    public BaseQuickAdapter getAdapter() {
        return new FollowAdapter(null);
    }

    @Override
    public void itemChildClick(BaseQuickAdapter baseQuickAdapter, View view, int position) {
        Follow follow = (Follow) baseQuickAdapter.getData().get(position);
        switch (view.getId()) {
            case R.id.iv_follow:
                showRunningDialog(R.string.committing);
                WuserinfoRequest wuserinfoRequest = new WuserinfoRequest();
                wuserinfoRequest.setWuserId(follow.getWuserId() + "");
                startTask(CommonBiz.getInstance().follow(wuserinfoRequest), baseResponse -> {
                    follow.setStatus(baseResponse.code);
                    ToastHelper.show(this, baseResponse.msg);
                    baseQuickAdapter.notifyItemChanged(position);
                });
                break;
        }
    }

    @Override
    public void itemClick(BaseQuickAdapter baseQuickAdapter, View view, int position) {
        if(!CommonBiz.getInstance().isLogin(this)) {
            startActivity(new Intent(this, LoginActivity.class));
            return;
        }
        Follow follow = (Follow) baseQuickAdapter.getData().get(position);
        startActivity(AnchorDetailActivity.newIntent(this, String.valueOf(follow.getWuserId())));
    }

    @Override
    public void getData() {
        startTask(CommonBiz.getInstance().myFans(), listBaseResponse -> {
            doSuc(listBaseResponse.data, listBaseResponse.totalPageCount);
        });
    }

    @Override
    protected void initView(Bundle savedInstanceState) {
        super.initView(savedInstanceState);
        ivRight.setImageResource(R.mipmap.ic_search_title);
        ivRight.setVisibility(View.VISIBLE);
    }
}
